package com.yeyks.websocket;

import cn.hutool.json.JSONUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.yeyks.common.constants.MessageConst;
import com.yeyks.common.em.WebSocketTypeEnum;
import com.yeyks.common.pojo.WebSocketBaseSendPojo;
import com.yeyks.common.result.OrderPickWebSocket;

/**
 * @author fuchangshuai
 * @date 2019/08/19 16:42
 */
public class SendMessageBean {
    /**
     * 订单websocket推送
     *
     * @param msg
     * @return
     */
    public static String getOrderMsg(String msg, Integer vipFlag) {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.ORDER.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("orderNo", msg, "vipFlag", vipFlag)));
        return JSONUtil.toJsonStr(pojo);
    }
    /**
     * b2c订单websocket推送
     *
     * @param orderNo
     * @return
     */
    public static String getB2cOrderSuccess(String orderNo) {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.B2C_ORDER_SUCCESS.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("orderNo", orderNo)));
        return JSONUtil.toJsonStr(pojo);
    }

    /**
     * 抢单websocket推送
     *
     * @param msg
     * @return
     */
    public static String getRobOrderMsg(String msg) {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.ROB_ORDER.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(msg);
        return JSONUtil.toJsonStr(pojo);
    }

    /**
     * 入住通知websocket推送
     *
     * @return
     */
    public static String getInformMsg() {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.INFORM.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("inform", MessageConst.ENROLL_HOTEL)));
        return JSONUtil.toJsonStr(pojo);
    }

    /**
     * 订单退款websocket推送
     *
     * @return
     */
    public static String getOrderRefundMsg() {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.ORDER_REFUND.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("orderRefund", WebSocketTypeEnum.ORDER_REFUND.desc())));
        return JSONUtil.toJsonStr(pojo);
    }

    /**
     * 抢单结果websocket推送
     *
     * @param msg
     * @return
     */
    public static String getRobOrderSuccessMsg(String msg) {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.ROB_ORDER_RESULT.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(msg);
        return JSONUtil.toJsonStr(pojo);
    }

    public static void main(String[] args) {
        WebSocketBaseSendPojo pojo = new WebSocketBaseSendPojo();
        pojo.setType(WebSocketTypeEnum.ORDER.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("orderId", "订单")));
        System.out.println(JSONUtil.toJsonStr(pojo));

        pojo.setType(WebSocketTypeEnum.ROB_ORDER.value());
        pojo.setTimestamp(System.currentTimeMillis());
        OrderPickWebSocket webSocket = new OrderPickWebSocket();
        webSocket.setRoomIds(Lists.newArrayList(7391,7376,7373));
        webSocket.setCheckIn(1565712000000L);
        webSocket.setPhone("15188445491");
        webSocket.setManualPickOrder(1);
        webSocket.setUserShowPrice(15000);
        webSocket.setHotelId(755);
        webSocket.setCheckOut(1565798400000L);
        webSocket.setUserId(263);
        webSocket.setOperatorId(2235);
        webSocket.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(webSocket));
        System.out.println(JSONUtil.toJsonStr(pojo));

        pojo.setType(WebSocketTypeEnum.INFORM.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("inform", MessageConst.ENROLL_HOTEL)));
        System.out.println(JSONUtil.toJsonStr(pojo));

        pojo.setType(WebSocketTypeEnum.ORDER_REFUND.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("orderRefund", WebSocketTypeEnum.ORDER_REFUND.desc())));
        System.out.println(JSONUtil.toJsonStr(pojo));

        pojo.setType(WebSocketTypeEnum.ROB_ORDER_RESULT.value());
        pojo.setTimestamp(System.currentTimeMillis());
        pojo.setDataStr(JSONUtil.toJsonStr(ImmutableMap.of("successMsg", "抢单", "failMsg", "抢单失败")));
        System.out.println(JSONUtil.toJsonStr(pojo));
    }

}
